package edu.umn.msse.farside.FourH.web;

import edu.umn.msse.farside.FourH.domain.Volunteer;
import edu.umn.msse.farside.FourH.services.EventService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpSession;

/**
 * Created by IntelliJ IDEA.
 * User: corcutt
 * Date: Mar 18, 2009
 * Time: 8:21:20 PM
 * To change this template use File | Settings | File Templates.
 */
@Controller
@RequestMapping("/myEvents")
public class AdminEventListController
{
    private EventService eventService;

    @Autowired
    public void setItemService(EventService eventService) {
        this.eventService = eventService;
    }

    @RequestMapping(method = RequestMethod.GET)
    public String prepareItemList(Model model, HttpSession session) {
        // this is what is provided to the futureEvents page ... all the items sold by the user
        model.addAttribute("events", eventService.getEventsForUser(getAdminUser(session)));
        return "myEvents";
    }

    private Volunteer getAdminUser(HttpSession session) {
        return (Volunteer) session.getAttribute("volunteer");
    }

}
